//
//  NetWorkRequestTest.m
//  NaRiLSVMT
//
//  Created by jmsre on 14-8-14.
//  Copyright (c) 2014年 helloyouth.org. All rights reserved.
//

#import "NetWorkRequestTest.h"
#import "MBProgressController.h"
#import "Network_Operation.h"
@implementation NetWorkRequestTest
+ (void)networkTestConnected {
    NSString *testConnectStr = [Network_API Network_API_TestConnected];
    
    NSLog(@"%@",testConnectStr);
    NSString    *str = [NSString stringWithFormat:@"[{\"classname\":%@,\"methodname\":%@,\"parameterClasss\":[%@]}]",@"\"iPadSettingService\"",@"\"testConnected\"",[NSString stringWithFormat:@"%@",@""]];
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [[Network_Operation httpClientWithUrl:testConnectStr] getPath:testConnectStr
                 parameters:@{@"jsonstr":str,
                              @"callback":@""
                                  }
                    success:^(AFHTTPRequestOperation *operation, id responseObject) {
                        sleep(1);
                        if([responseObject isKindOfClass:[NSString class]])
                        {
                            NSString *resStr = [NSString stringWithString:responseObject];
                            if(!([resStr rangeOfString:@"true"].location == NSNotFound))
                            {
                                //call TCP connect:
                                NSLog(@"NetWork Success");
                                testConnectSucess = YES;
                             //  sleep(2);
                                if(isTesthttp)
                                    [[MBProgressController sharedInstance] showTipsOnlyText:@"测试数据服务成功!"
                                                                                   AndDelay:1.5];
                            }
                            else
                            {
                              //  dispatch_async(dispatch_get_main_queue(), ^{
                                  //  [[MBProgressController sharedInstance] hide];
                                  //   sleep(2);
                                    [[MBProgressController sharedInstance] showTipsOnlyText:@"网络出错" AndDelay:1.5];
                                   // [[MBProgressController sharedInstance] hide];
                              //  });
                                NSLog(@"直接返回");
                                testConnectSucess = NO;
                                return;
                            }
                        }
                        else {
                           // dispatch_async(dispatch_get_main_queue(), ^{
                               // [[MBProgressController sharedInstance] hide];
                                // sleep(2);
                                [[MBProgressController sharedInstance] showTipsOnlyText:@"网络出错"
                                                                               AndDelay:1.5];
                               //[[MBProgressController sharedInstance] hide];
                           // });
                            NSLog(@"直接返回");
                            testConnectSucess = NO;
                           // return;
                        }
                    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                        //dispatch_async(dispatch_get_main_queue(), ^{
                          //  [[MBProgressController sharedInstance] hide];
                             sleep(1);
                            [[MBProgressController sharedInstance] showTipsOnlyText:@"网络出错"
                                                                           AndDelay:1.5];
                            //[[MBProgressController sharedInstance] hide];
                       // });
                        testConnectSucess = NO;
                        return;
                    }];
    });
    //[[MBProgressController sharedInstance] hide];
}
@end
